package com.frikinet.tools.gui;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.KeyStroke;

import com.frikinet.tools.i18n.FI18N;
import com.frikinet.tools.i18n.Translable;

public class FCheckBoxMenuItem extends JCheckBoxMenuItem implements Translable, Indexable
{
	private static final long serialVersionUID = 1L;

	private FI18N i18n = null;
	private String id = "";

	public FI18N getI18n()
	{
		return i18n;
	}

	public void setI18N(FI18N i18n)
	{
		this.i18n = i18n;
	}
	
	public void translate()
	{
		String text = getText();
		if(i18n != null)
			super.setText(parseName(i18n.translate(text)));
		else
			super.setText(parseName(text));
	}
	
	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	private String parseName(String text)
	{
		String stripString = text.replaceAll("_", "");
		int index = text.indexOf('_');
		if(index >= 0)
			setMnemonic(text.charAt(index+1));
		return stripString;
	}
	
	public void setAcceleratorString(String keys)
	{
		setAccelerator(KeyStroke.getKeyStroke(keys));
	}
}
